home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Text and Fonts / TrimmingTheText / TrimmingTheText.cs next >
Encoding:
Text File  |  2001-01-15  |  2.5 KB  |  67 lines

  1. //----------------------------------------------
  2. // TrimmingTheText.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class TrimmingTheText:PrintableForm
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new TrimmingTheText());
  13.      }
  14.      public TrimmingTheText()
  15.      {
  16.           Text = "Trimming the Text";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           Brush        brush  = new SolidBrush(clr);
  21.           float        cyText = Font.GetHeight(grfx);
  22.           float        cyRect = cyText;
  23.           RectangleF   rectf  = new RectangleF(0, 0, cx, cyRect);
  24.           string       str    = "Those who profess to favor freedom and " +
  25.                                 "yet depreciate agitation. . .want " +
  26.                                 "crops without plowing up the ground, " +
  27.                                 "they want rain without thunder and " +
  28.                                 "lightning. They want the ocean without " +
  29.                                 "the awful roar of its many waters. " +
  30.                                 "\x2014 Frederick Douglass";
  31.           StringFormat strfmt = new StringFormat();
  32.  
  33.           strfmt.Trimming = StringTrimming.Character;
  34.           grfx.DrawString("Character: " + str, Font, brush, rectf, strfmt);
  35.  
  36.           rectf.Offset(0, cyRect + cyText);
  37.  
  38.           strfmt.Trimming = StringTrimming.Word;
  39.           grfx.DrawString("Word: " + str, Font, brush, rectf, strfmt);
  40.  
  41.           rectf.Offset(0, cyRect + cyText);
  42.  
  43.           strfmt.Trimming = StringTrimming.EllipsisCharacter;
  44.           grfx.DrawString("EllipsisCharacter: " + str, 
  45.                           Font, brush, rectf, strfmt);
  46.  
  47.           rectf.Offset(0, cyRect + cyText);
  48.  
  49.           strfmt.Trimming = StringTrimming.EllipsisWord;
  50.           grfx.DrawString("EllipsisWord: " + str, 
  51.                           Font, brush, rectf, strfmt);
  52.  
  53.           rectf.Offset(0, cyRect + cyText);
  54.  
  55.           strfmt.Trimming = StringTrimming.EllipsisPath;
  56.           grfx.DrawString("EllipsisPath: " + 
  57.                           Environment.GetFolderPath
  58.                                (Environment.SpecialFolder.Personal),
  59.                           Font, brush, rectf, strfmt);
  60.  
  61.           rectf.Offset(0, cyRect + cyText);
  62.  
  63.           strfmt.Trimming = StringTrimming.None;
  64.           grfx.DrawString("None: " + str, Font, brush, rectf, strfmt);
  65.      }
  66. }
  67.